/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reportcenter.support.dbutil;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author renan_luz
 */
public class JPAFactory {
    
    private EntityManagerFactory factory;
    private EntityManager manager;
    private static JPAFactory jpa;
    
    public static JPAFactory getInstance(){
        if (jpa == null){
            jpa = new JPAFactory();
        }
        return jpa;
    }
    
    private JPAFactory(){
        
    }

    public EntityManager getManager() {
        return manager;
    }

    public void setManager(EntityManager manager) {
        this.manager = manager;
    }
    
    
   
    public void init() {
        factory = Persistence.createEntityManagerFactory("ReportCenter2PU");
        manager = factory.createEntityManager();
    }
    
    public void shutdown() {
        manager.close();
        factory.close();
    }

}
